package com.medicine.hbp.sp;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;

import com.medicine.hbp.mob.InterestListVo;

import android.content.Context;
import android.content.SharedPreferences;

/**
 *标签集合
 * @author Administrator
 *
 */
public class InterestSp {
	private static final String INTEREST_SP="interest_sp";

	private static final String INTEREST="Interest";

	private static final String INTEREST_NAME="name";
	private static final String INTEREST_ID="id";
	private static final String INTEREST_TYPE="type";
	private static final String INTEREST_YORN="yorn";
	private static SharedPreferences preferences;

//	public static void exitUser(Context context){
//		preferences = context.getSharedPreferences(LOGIN_SP,Context.MODE_PRIVATE);
//		preferences.edit().clear().commit();
//	}
	/**
	 * 已收藏的标签集合
	 */
	public static List<InterestListVo>  getInterest(Context context) {
		List<InterestListVo> info=new ArrayList<InterestListVo>();
		preferences = context.getSharedPreferences(INTEREST_SP,Context.MODE_PRIVATE);
		try {
			JSONArray jsonArray=new JSONArray(preferences.getString(INTEREST, ""));
			for (int i = 0; i < jsonArray.length(); i++) {
				InterestListVo vo=new InterestListVo();
				vo.appTypeId=jsonArray.getJSONObject(i).getInt("appTypeId");
				vo.appTypeName=jsonArray.getJSONObject(i).getString("appTypeName");
				info.add(vo);
			}
			return info;
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return null;
	}
	/**
	 * 已收藏的标签集合
	 */
	public static String getInterestTypeList(Context context) {
		String type="";
		List<InterestListVo> info=getInterest(context);
		for (int i = 0; i < info.size(); i++) {
			type+=info.get(i).appTypeId+",";
		}
		return type.substring(0, type.length()-1);
	}

	/**
	 * 存储标签的json
	 * @param Interest json字符串
	 * @param context
	 */
	public static void setInterest(String Interest,Context context) {
		preferences = context.getSharedPreferences(INTEREST_SP,Context.MODE_PRIVATE);
		preferences.edit().putString(Interest, Interest).commit();
	}
	/**
	 * 标签名称存储
	 */
	public static void setInterestName(String name,Context context) {
		preferences = context.getSharedPreferences(INTEREST_SP,Context.MODE_PRIVATE);
		preferences.edit().putString(INTEREST_NAME, name).commit();
	}
	/**
	 * 标签id存储
	 */
	public static void setInterestId(String id,Context context) {
		preferences = context.getSharedPreferences(INTEREST_SP,Context.MODE_PRIVATE);
		preferences.edit().putString(INTEREST_ID, id).commit();
	}
	/**
	 * 标签名称读取
	 */
	public static String getInterestName(Context context) {
		preferences = context.getSharedPreferences(INTEREST_SP,Context.MODE_PRIVATE);
		return preferences.getString(INTEREST_NAME, "");
	}
	/**
	 * 标签id读取
	 */
	public static String getInterestId(Context context) {
		preferences = context.getSharedPreferences(INTEREST_SP,Context.MODE_PRIVATE);
		return preferences.getString(INTEREST_ID, "");
	}


	/**
	 * 病种筛选    0不传   1  传 单个参数   2 传多个参数
	 */
	public static void setInterestType(int type,Context context) {
		preferences = context.getSharedPreferences(INTEREST_SP,Context.MODE_PRIVATE);
		preferences.edit().putInt(INTEREST_TYPE, type).commit();
	}
	/**
	 * 病种筛选    0不传   1  传 单个参数   2 传多个参数
	 */
	public static int getInterestType(Context context) {
		preferences = context.getSharedPreferences(INTEREST_SP,Context.MODE_PRIVATE);
		return preferences.getInt(INTEREST_TYPE, -1);
	}

	/**
	 * 是否有权限 y有   n 无
	 */
	public static void setInterestYorN(String type,Context context) {
		preferences = context.getSharedPreferences(INTEREST_SP,Context.MODE_PRIVATE);
		preferences.edit().putString(INTEREST_YORN, type).commit();
	}
	/**
	 *是否有权限 y有   n 无
	 */
	public static String getInterestYorN(Context context) {
		preferences = context.getSharedPreferences(INTEREST_SP,Context.MODE_PRIVATE);
		return preferences.getString(INTEREST_YORN, "");
	}

//	
}
